Listing A: The bfs.java Program // bfs.java // demonstrates breadth-first search // to run this program: C>java BFSApp //////////////////////////////////////////////////////////////// class Queue { private final int SIZE = 20; private int[] queArray; private int front; private int rear; // ------------------------------------------------------------- public Queue() // constructor { queArray = new int[SIZE]; front = 0; rear = -1; } // ------------------------------------------------------------- public void insert(int j) // put item at rear of queue { if(rear == SIZE-1) rear = -1; queArray[++rear] = j; } // ------------------------------------------------------------- public int remove() // take item from front of queue { int temp = queArray[front++]; if(front == SIZE) front = 0; return temp; } // ------------------------------------------------------------- public boolean isEmpty() // true if queue is empty { return ( rear+1==front || (front+SIZE-1==rear) ); } // ------------------------------------------------------------- } // end class Queue //////////////////////////////////////////////////////////////// class Vertex { public char label; // label (e.g. ‘A’) public boolean wasVisited; // ------------------------------------------------------------- public Vertex(char lab) // constructor { label = lab; wasVisited = false; } // ------------------------------------------------------------- } // end class Vertex //////////////////////////////////////////////////////////////// class Graph { private final int MAX_VERTS = 20; private Vertex vertexList[]; // list of vertices private int adjMat[][]; // adjacency matrix private int nVerts; // current number of vertices private Queue theQueue; // ------------------ public Graph() // constructor { vertexList = new Vertex[MAX_VERTS]; // adjacency matrix adjMat = new int[MAX_VERTS][MAX_VERTS]; nVerts = 0; for(int j=0; jjava MSTApp //////////////////////////////////////////////////////////////// class StackX { private final int SIZE = 20; private int[] st; private int top; // ------------------------------------------------------------- public StackX() // constructor { st = new int[SIZE]; // make array top = -1; } // ------------------------------------------------------------- public void push(int j) // put item on stack { st[++top] = j; } // ------------------------------------------------------------- public int pop() // take item off stack { return st[top--]; } // ------------------------------------------------------------- public int peek() // peek at top of stack { return st[top]; } // ------------------------------------------------------------- public boolean isEmpty() // true if nothing on stack { return (top == -1); } // ------------------------------------------------------------- } // end class StackX //////////////////////////////////////////////////////////////// class Vertex { public char label; // label (e.g. ‘A’) public boolean wasVisited; // ------------------------------------------------------------- public Vertex(char lab) // constructor { label = lab; wasVisited = false; } // ------------------------------------------------------------- } // end class Vertex //////////////////////////////////////////////////////////////// class Graph { private final int MAX_VERTS = 20; private Vertex vertexList[]; // list of vertices private int adjMat[][]; // adjacency matrix private int nVerts; // current number of vertices private StackX theStack; // ------------------------------------------------------------- public Graph() // constructor { vertexList = new Vertex[MAX_VERTS]; // adjacency matrix adjMat = new int[MAX_VERTS][MAX_VERTS]; nVerts = 0; for(int j=0; j